<?php
require_once 'Zend/Controller/Action.php';

class ProductapiController extends App_Zend_Controller_Action_Shop
{
	public function indexAction()
	{
		
	}
	
	public function getnotifyAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		
		$itemid = $this->getRequest()->getParam('id',0);
		$type = $this->getRequest()->getParam('type', '');
		
		if ($itemid && $type) {
			$notifyInfo = new CNotifyinfo();
			$notifyInfo->insert(array('itemid'=>$itemid, 'type'=>$type, 'add_time'=>time()));
			echo 'ok';
		}
	}
	
	public function cronjobAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		set_time_limit(0);
		ignore_user_abort();
		$notifyInfo = new CNotifyinfo();
		
		$rows = $notifyInfo->fetchAll(array('is_check = ?'=>0));
		$item = new CItem();
		$db = $item->getAdapter();
		foreach ($rows as $v) {
			$act = $v->type;
			if ($v->type == 'mod') {
				$tmp = $db->fetchRow('select * from zcshop_items where fromitemid=' . $v->itemid);
				if (!$tmp) {
					$act = 'add';
				}
			}
			if ($act == 'add') {
				$notifyInfo->addProduct($v->itemid);
			} else {
				$notifyInfo->updateProduct($v->itemid);
			}
			$notifyInfo->update(array('is_check'=>'1'), 'info_id=' . $v->info_id);
		}
		if (count($rows) > 0) {
			$notifyInfo->other();
		}
	}
}